import { CompanyType } from "./../types/job.d";
import { CategoryType } from "../types/job";
import request from "../utils/request";

// 发布分类
export const categoryPost = (cateObj: Omit<CategoryType, "objectId">) => {
  return request.post("classes/VueClassify", cateObj);
};

// 企业入驻
export const companyPost = (companyObj: CompanyType) => {
  return request.post("classes/VueCompany", companyObj);
};

//岗位列表
interface WhereType {
  jobName: { $regex: string; $options: "i" };
  lv1: string;
}
export const jobGet = (
  page: number = 1,
  size: number = 10,
  condition?: { name: string; cate: string }
) => {
  let skip = (page - 1) * size;
  let where: WhereType = {
    // jobName:{"$regex":condition.jobName,"$options":"i"}
    // jobName:''   //后端就会尝试去找岗位名称为空的数据，导致无法拿到数据
  } as WhereType;
  //携带岗位名称
  if (condition && condition.name) {
    where.jobName = { $regex: condition.name, $options: "i" };
  }
  //携带分类名称
  if (condition && condition.cate) {
    where.lv1 = condition.cate;
  }
  let query = JSON.stringify(where);
  return request.get(`classes/VueJob?where=${query}`, {
    params: {
      limit: size,
      count: 1, //开启对象计数（数据表总条数）
      skip,
    },
  });
};

//饼状图数据请求
export const chartGet = () => {
  return request.get("classes/VueChart");
};
